
<template>
    <div id="upload_image">
        <h1>手动上传</h1>
        <el-upload
                action="#"
                list-type="picture-card"
                :auto-upload="false"
                drag
                :on-change="handleChange"
                ref="pictureUpload">
            <i slot="default" class="el-icon-plus"></i>
            <div slot="file" slot-scope="{file}">
                <img
                        class="el-upload-list__item-thumbnail"
                        :src="file.url" alt="" >
                <span class="el-upload-list__item-actions">
                    <span
                            class="el-upload-list__item-preview"
                            @click="handlePictureCardPreview(file)"
                    >
                      <i class="el-icon-zoom-in"></i>
                    </span>
                    <span
                            v-if="!disabled"
                            class="el-upload-list__item-delete"
                            @click="handleDownload(file)"
                    >
                      <i class="el-icon-download"></i>
                    </span>
                    <span
                            v-if="!disabled"
                            class="el-upload-list__item-delete"
                            @click="handleRemove(file)"
                    >
                      <i class="el-icon-delete"></i>
                    </span>
                </span>
            </div>
        </el-upload>
        <el-button style="margin-top: 60px" @click="editImg()">细化图像边缘</el-button>
        <el-dialog :visible.sync="dialogVisible">
            <img width="100%" height="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
    </div>
</template>

<script>
import {hello, infer} from "./addon"
const { ipcRenderer } = require('electron')
    export default {
        name: "UploadFile",
        data() {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                disabled: false,
                fileList: []
            };
        },
      mounted() {
        ipcRenderer.on('main-msg', (event, arg) => {
          console.log(arg) // prints "好的"
        })
      },
      methods: {
            handleRemove(file) {
                this.$refs.pictureUpload.handleRemove(file)

            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            },
            handleDownload(file) {
                console.log(file);
            },
            handleChange(file, fileList) {
                this.fileList = fileList
            },
            editImg() {
                //跳转到编辑图片组件
                //传递上传图片路径
                console.log(this.fileList)
                // ipcRenderer.on('main-msg', (event, arg) => {
                //   console.log(arg) // prints "好的"
                // })
              let param = new Array()
              for (let i=0; i<this.fileList.length; i++) {
                param[i] = this.fileList[i].raw.path
              }
                ipcRenderer.send('renderer-msg', param)
                //hello();
                this.$router.replace({path: '/edit', query: {fileList: this.fileList}})
            }
        }
    }
</script>

<style scoped>
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }
    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }
    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
    .el-upload-list__item-thumbnail {
        height: 80%;
        width: 100%;
    }
</style>